import request from '@/utils/request'
// import { Notification } from 'element-ui'

export function updateInvitation (invitationKey, accept = true) {
  return request({
    url: '/invitation/' + invitationKey,
    method: 'delete',
    params: {
      accept: accept
    }
  })
}

export function loadInvitations () {
  return request({
    url: '/invitations',
    method: 'get'
  })
}

export function sendInvitation (projectId, userIdOrAccount) {
  return request({
    url: '/project/' + projectId + '/invitation',
    method: 'post',
    params: {
      userIdOrAccount: userIdOrAccount
    }
  })
}

/**
 * 获取用户所参与或创建的项目
 */
export function getProjects () {
  return request({
    url: '/projects',
    method: 'get'
  })
}

export function getProjectData (projectId) {
  return request({
    url: '/project/' + projectId,
    method: 'get'
  })
}

export function getProjectMembers (projectId) {
  return request({
    url: '/project/' + projectId + '/members',
    method: 'get'
  })
}

export function addProject (formData) {
  return request({
    url: '/project',
    method: 'post',
    data: {
      name: formData.name,
      description: formData.description
    }
  })
}

export function updateProject (formData, projectId) {
  let data = {}
  if (formData.name) {
    data['name'] = formData.name
  }
  if (formData.description) {
    data['description'] = formData.description
  }
  if (formData.enable) {
    data['enable'] = formData.enable
  }
  if (formData.state) {
    data['state'] = formData.state
  }
  return request({
    url: '/project/' + projectId,
    method: 'put',
    data: data
  })
}

export function exitProject (projectId, userId) {
  return request({
    url: '/project/' + projectId + '/member/' + userId,
    method: 'delete'
  })
}
